//
//  HomeStrangCollionViewController.m
//  CheekiOS
//
//  Created by mac on 2017/5/23.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HomeStrangCollionViewController.h"
//状态瀑布流
#import "FWBLayout.h"
#import "FWBCollectionViewCell.h"
//模型
#import "StrangerInfoModel.h"
#import "MessageModelManager.h"
//放大图片
#import "MJPhotoBrowser.h"
//拉黑。。。举报
#import "GGActionSheet.h"
#import "AlertViewExtension.h"
#import "ZXYAlertView.h"
//请求
#import "HcardHttpmanager.h"
//导航栏
#import "UINavigationBar+Transparent.h"
//Cell 个人资料
#import "StrangerdataCell.h"
//公开相册
#import "PPImageScrollingTableViewCell.h"
//状态详情
#import "MstrangdetailsViewController.h"
//聊天
#import "HQConversationViewController.h"
//送礼物
#import "HRGiftView.h"
//充值
#import "UserAccountViewController.h"
//送礼物加好友提示
#import "CheekMessageAlertView.h"


static NSString * ident = @"FWBCollectionViewCell";
static NSString * StrangerCell = @"strangerCell";
static NSString * CellIdentifier = @"PPImageScrollingCell";
static NSString * titleCellident = @"titleCell";
static NSString * imageCellIdent = @"imageCellIdent";

static CGFloat kHomeImgHeight = 260;

#define ValidStr(f) (f!=nil && [f isKindOfClass:[NSString class]] && ![f isEqualToString:@""])

@interface HomeStrangCollionViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,ZXYAlertViewDelegate,alertviewExtensionDelegate,GGActionSheetDelegate,PPImageScrollingTableViewCellDelegate,CAAnimationDelegate,StrangerdataCellDelegate,HRGiftViewDelegate,CheekMessageAlertViewDelegate>

/** 瀑布流约束 */
@property (nonatomic, strong) UICollectionView * collectionView;
@property (nonatomic, strong) FWBLayout * collectionLayout;
/** 状态数据 */
@property (nonatomic, strong) NSMutableArray * dataSource;
/** 头部图片 */
@property (nonatomic, strong) UIImageView * headerImageView;
/** 数据模型 */
@property (nonatomic, strong) HRSDUserInfo *infoModel;
/** 拉黑举报 */
@property (nonatomic, strong) GGActionSheet *actionSheetTitle;
@property (nonatomic, strong) AlertViewExtension *alert;
@property (nonatomic, strong) ZXYAlertView *alertX;
@property (nonatomic, strong) NSArray *reportArr;
/** 图片数组 */
@property (nonatomic, strong) NSMutableArray *photoArr;
/** 右侧点击按钮 */
@property (nonatomic, strong) UIButton *rightBtn;
/** 个性签名 */
@property (nonatomic, strong) UILabel *signatureLab;
/** 礼物按钮 */
@property (nonatomic, strong) UIButton *giftBtn;
/**
 礼物View
 */
@property (nonatomic, strong) HRGiftView *giftView;
@property (nonatomic, strong) UIView *giftBView;
@property (nonatomic, strong) CheekGiftModel *giftModel;
/**
 弹框
 */
@property (nonatomic, strong)CheekMessageAlertView *messageAlert;




@end

@implementation HomeStrangCollionViewController


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
    [self.navigationController.navigationBar setTranslucent:YES];
    [self.navigationController.navigationBar js_setBackgroundColor:[UIColor clearColor]];
    
    [self setNavgationBarHidden];
    [self setNavgationBarHiddenNo];
    
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor], NSFontAttributeName : FontP(15)};
    
    [self setTabaritmimageStr:@"back_w"];
    
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar js_reset];
    
}
//让HeaderimageView去最下层
- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    if (self.collectionView) {
        [self.collectionView sendSubviewToBack:self.headerImageView];
    }
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self configColectionView];
}

/**
 初始化colectionView
 */
- (void)configColectionView{
    
    _reportArr = @[@"淫秽色情",@"政治反动",@"语言暴力",@"广告欺诈",@"虚假性别",@"其他内容",@"取消"];
    
    
    self.collectionLayout = [[FWBLayout alloc] init];
    self.collectionLayout.lineNumber = 2; //列数
    self.collectionLayout.rowSpacing = 10; //行间距
    self.collectionLayout.lineSpacing = 10; //列间距
    self.collectionLayout.sectionInset = UIEdgeInsetsMake(10, 15, 10, 15);
    
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0,KScreenWidth, KScreenHeight) collectionViewLayout:self.collectionLayout];
    [self.collectionView registerClass:[StrangerdataCell class] forCellWithReuseIdentifier:StrangerCell];
    [self.collectionView registerClass:[PPImageScrollingTableViewCell class] forCellWithReuseIdentifier:CellIdentifier];
    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:titleCellident];
    [self.collectionView registerClass:[FWBCollectionViewCell class] forCellWithReuseIdentifier:ident];
    [self.collectionLayout registerClass:[UICollectionViewCell class] forDecorationViewOfKind:@"imgaeViewcell"];
    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:imageCellIdent];

    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    [self.view addSubview:self.collectionView];
    
    //返回每个cell的高   对应indexPath
    __weak typeof (self)weakSelf = self;
    [self.collectionLayout computeIndexCellHeightWithWidthBlock:^CGFloat(NSIndexPath *indexPath, CGFloat width) {
        
        if (indexPath.section == 0) {
            if (_infoModel) {
                int lines = 0;
                if (_infoModel.skill.length > 0) {
                    lines++;
                }
                if (ValidStr(_infoModel.job) || ValidStr(_infoModel.affection) || ValidStr(_infoModel.height) || ValidStr(_infoModel.weight)) {
                    lines++;
                }
                return firstSectionCellH*SCREEN_WIDTH_RATIO47 + oneLineHeight*lines;
            }
            return firstSectionCellH*SCREEN_WIDTH_RATIO47;
        }
        if (indexPath.section == 1) {
            return sectionSectionCellH;
        }
        if (indexPath.section == 2){
            return sectionsectioncellHH;
        }
 
        
        if (weakSelf.dataSource.count==0) {
            return 260;
        }
        
            
        
        
        HRTimeLineModel *timeLineModel = self.dataSource[indexPath.row];
        
        Active *model = [Active getActiveWithDictionary:(NSDictionary *)timeLineModel.active];
        
        if (model.img.length > 0 && model.content.length > 0) {
            return (cellTextH + cellImageH+cellHeadTuneH)*SCREEN_WIDTH_RATIO47;
        }
        if (model.img.length > 0) {
            return (cellImageH+cellHeadTuneH)*SCREEN_WIDTH_RATIO47;
        }
        return (cellTextH+cellHeadTuneH)*SCREEN_WIDTH_RATIO47;
    }];
    
    
    self.collectionView.backgroundColor = ColorI(0xf6f6f6);
    //头部
    _headerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, -kHomeImgHeight*SCREEN_WIDTH_RATIO47, self.view.frame.size.width, kHomeImgHeight*SCREEN_WIDTH_RATIO47)];
    
    _headerImageView.contentMode = UIViewContentModeScaleAspectFill;
    _headerImageView.clipsToBounds = YES;
    
    
    UIView *view = [UIView new];
    [self.headerImageView addSubview:view];
    view.backgroundColor = [UIColor blackColor];
    view.alpha = 0.6;
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.top.mas_equalTo(self.headerImageView);
    }];
    
    
    
    
    
    [self.collectionView setContentInset:UIEdgeInsetsMake(kHomeImgHeight*SCREEN_WIDTH_RATIO47, 0, 0, 0)];
    [self.collectionView addSubview:_headerImageView];
    
    
    [self sendRequest];
    [self activeListRequest];
    

    
    
    _rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _rightBtn.frame = CGRectMake(0, 0, 50*SCREEN_WIDTH_RATIO47, 35*SCREEN_WIDTH_RATIO47);
    [_rightBtn setTitle:@"···" forState:UIControlStateNormal];
    _rightBtn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight ;//设置文字位置，现设为居左，默认的是居中
    [_rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _rightBtn.titleLabel.font = FontBold(20);
    [_rightBtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_rightBtn];
    self.navigationItem.rightBarButtonItem =rightBarButtonItem;
    CGFloat videoFont ;
    
    if (iPhone5) {
        videoFont = 8;
    }else if (iPhone6){
        videoFont = 9;
        
    }else {
        videoFont = 11;
        
    }
    //个性签名
    _signatureLab = [[UILabel alloc] init];
    _signatureLab.textColor = [UIColor whiteColor];
    _signatureLab.textAlignment = NSTextAlignmentCenter;
    _signatureLab.font = FontP(12);
    [_headerImageView addSubview:_signatureLab];
    [_signatureLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_headerImageView).offset(75);
        make.width.mas_equalTo(KScreenWidth);
        make.height.mas_equalTo(25*SCREEN_WIDTH_RATIO47);
    }];
    
   
    UIButton *videobtn = [UIButton buttonWithType:UIButtonTypeCustom];
    videobtn.titleLabel.font = FontBold(videoFont);
    if ([_infoModel.videoStatus isEqualToString:@"1"]) {
        [videobtn setImage:[UIImage imageNamed:@"stranger_play_att"] forState:UIControlStateNormal];
        
        [videobtn setTitle:@"视频已认证" forState:UIControlStateNormal];
        videobtn.hidden = NO;

    } else {
        videobtn.hidden = YES;
        [videobtn setImage:[UIImage imageNamed:@"stranger_id_wa_button"] forState:UIControlStateNormal];
        
        [videobtn setTitle:@"视频未认证" forState:UIControlStateNormal];
    }
    
    videobtn.imageEdgeInsets = UIEdgeInsetsMake(0, -8, 0, 0);
    videobtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -6);
    
    [videobtn setTitleColor:TheLinColor forState:UIControlStateNormal];
    videobtn.layer.cornerRadius = 10.0;
    videobtn.layer.borderWidth = 0.5f;
    videobtn.layer.borderColor = [[UIColor whiteColor]CGColor];
    [_headerImageView addSubview:videobtn];
    
    [videobtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_headerImageView).offset(-15*SCREEN_WIDTH_RATIO47);
        make.width.mas_equalTo(80*SCREEN_WIDTH_RATIO47);
        make.height.mas_equalTo(20*SCREEN_WIDTH_RATIO47);
        make.bottom.equalTo(_headerImageView.mas_bottom).offset(-84*SCREEN_WIDTH_RATIO47);
    }];
    
    
    
    UIButton *cardButton = [UIButton buttonWithType:UIButtonTypeCustom];
    cardButton.titleLabel.font = FontBold(videoFont);
    
    if ([_infoModel.cardImgStatus isEqualToString:@"1"]) {
        
        [cardButton setTitle:@"身份已认证" forState:UIControlStateNormal];
        
        [cardButton setImage:[UIImage imageNamed:@"stranger_id_att"] forState:UIControlStateNormal];
        
        cardButton.hidden = NO;
    } else {

        cardButton.hidden = YES;
        
        [cardButton setTitle:@"身份未认证" forState:UIControlStateNormal];
        
        [cardButton setImage:[UIImage imageNamed:@"stranger_id_wa_button"] forState:UIControlStateNormal];

    }
    [cardButton setTitleColor:TheLinColor forState:UIControlStateNormal];
    cardButton.layer.cornerRadius = 10.0;
    cardButton.layer.borderWidth = 0.5f;
    cardButton.layer.borderColor = [[UIColor whiteColor]CGColor];
    cardButton.imageEdgeInsets = UIEdgeInsetsMake(0, -8, 0, 0);
    cardButton.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -6);
    
    [_headerImageView addSubview:cardButton];
    
    [cardButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_headerImageView).offset(-15*SCREEN_WIDTH_RATIO47);
        make.width.mas_equalTo(80*SCREEN_WIDTH_RATIO47);
        make.height.mas_equalTo(20*SCREEN_WIDTH_RATIO47);
        make.top.equalTo(videobtn.mas_bottom).offset(5);
    }];
    
 

    //礼物按钮
    _giftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _giftBtn.frame = CGRectMake(KScreenWidth-95, KScreenHeight-120, 80, 80);
    [_giftBtn setBackgroundImage:[UIImage imageNamed:@"stranger_gift_button"] forState:UIControlStateNormal];
    [_giftBtn addTarget:self action:@selector(giftBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_giftBtn];
  


}

#pragma mark =====================网络数据请求====================
//送礼物
- (void)giftBtnClick{

    if (_infoModel.isFriend == 0&&![[NSString stringWithFormat:@"%@",_infoModel.uid] isEqualToString:[HQHttpManager getUserId]]) {

        
            _giftBView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
        
        
            _giftView = [[HRGiftView alloc] initWithFrame:CGRectMake(0, _giftBView.height-230*SCREEN_WIDTH_RATIO47, KScreenWidth, 230*SCREEN_WIDTH_RATIO47)];
            _giftView.delegate = self;
            _giftView.timeType = @"0";
        
        
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            [button addTarget:self action:@selector(buttongiftBViewRemove) forControlEvents:UIControlEventTouchUpInside];
            button.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight-_giftView.height);
            [_giftBView addSubview:button];
        
        
            CATransition *animation = [CATransition  animation];
            
            animation.duration = 0.2f;
            animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
            animation.type = kCATransitionPush;
            animation.subtype = kCATransitionFromTop;
            [_giftBView.layer addAnimation:animation forKey:@"animation1"];
            [_giftBView  addSubview:_giftView];
            [self.view addSubview:_giftBView];
        
    }
    _giftView.isShow = NO;


}
- (void)buttongiftBViewRemove{
    
    _giftView.hidden = YES;
    _giftBView.hidden= YES;
    _giftView.isShow =NO;
    CATransition *animation = [CATransition  animation];
    
    animation.duration = 0.2f;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    animation.type = kCATransitionPush;
    animation.subtype = kCATransitionFromBottom;
    [self.giftBView.layer addAnimation:animation forKey:@"animtion2"];
    [UIView animateWithDuration:0.2 animations:^{
        
    }completion:^(BOOL finished) {
        [_giftView removeFromSuperview];
        [_giftBView removeFromSuperview];
    }];


}
- (void)didClickSendButton:(CheekGiftModel *)gift{
    _giftModel =gift;

    self.messageAlert = [[CheekMessageAlertView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
    self.messageAlert.delegate = self;
    
    NSString *giftName = [NSString stringWithFormat:@"确认送给TA%@吗?",_giftModel.name];
    
        [self.messageAlert CheekAlertTitle:@"对方接收礼物即可成为好友" text:giftName determineTitle:@"确定" determineBtnTage:1];
   
    [self animationWithView:self.messageAlert duration:0.3];
    
    [UIView animateWithDuration:0.25 animations:^{
        self.messageAlert.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
        
        
        [self.view addSubview:self.messageAlert];
    }];

    
    
}
//取消
-(void)removeBtn:(UIButton *)sender{
    
    [self.messageAlert removeFromSuperview];
}
//确定
-(void)determine:(UIButton *)sender{
    
    //判断是否是好友
    [self.messageAlert removeFromSuperview];
    
    WEAKSELF
    _giftView.isShow = YES;
    
    [HcardHttpmanager getuserInfocharmsuccess:^(id sucess) {
        UserInfocharmModel *model = sucess;
        NSInteger modelCharm = [model.charm intValue];
        NSInteger giftCharm = [weakSelf.giftModel.charm intValue];
        if (modelCharm > giftCharm) {
            
            [HcardHttpmanager giveGiftWithWid:_infoModel.uid WithGiftId:weakSelf.giftModel.giftId WithStatus:@"1" WithAskId:nil Success:^(id result) {
                
                if ([result[@"code"] isEqualToString:@"ok"]) {
                    [SVProgressHUD showSuccessWithStatus:@"礼物赠送成功"];
                    [weakSelf buttongiftBViewRemove];
                }
                
                
            } failure:^(NSError *error) {
                
            }];
            
        }else{
            [weakSelf buttongiftBViewRemove];
            UserAccountViewController *vc = [[UserAccountViewController alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        }
        
    } failure:^(NSError *error) {
        
    }];
   
    
    
}

- (void)animationWithView:(UIView *)view duration:(CFTimeInterval)duration{
    
    CAKeyframeAnimation * animation;
    animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
    animation.duration = duration;
    animation.removedOnCompletion = NO;
    
    animation.fillMode = kCAFillModeForwards;
    
    NSMutableArray *values = [NSMutableArray array];
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]];
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)]];
    //    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 0.9)]];
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
    
    animation.values = values;
    animation.timingFunction = [CAMediaTimingFunction functionWithName: @"easeInEaseOut"];
    
    [view.layer addAnimation:animation forKey:nil];
}


- (void)didClickRechargeButton{
    [self buttongiftBViewRemove];
    UserAccountViewController *vc = [[UserAccountViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)sendRequest{
    WEAKSELF
    _photoArr = [[NSMutableArray alloc]init];
    _dataSource = [[NSMutableArray alloc] init];
    [HQHttpManager sInfoWithUid:_UserId myId:[HQHttpManager getUserId]
                   successBlock:^(BOOL isSuccess, NSDictionary *resultDic) {
                       
                       _infoModel = [HRSDUserInfo getSDUserInfoWithDictionary:resultDic];
                       
                       [weakSelf setTitle:_infoModel.nickName];
                       
                       if (_infoModel.motto) {
                           NSString *str = _infoModel.motto;
                           if (str.length >15) {
                                NSString *strr =[str substringWithRange:NSMakeRange(0, 15)];
                               _signatureLab.text = [NSString stringWithFormat:@"%@...",strr];
                           }else{
                               
                               _signatureLab.text = str;
                           }
                       }else{
                           _signatureLab.text = @"TA还没填写个性签名";
                       }
                       
                       [_headerImageView sd_setImageWithURL:[NSURL URLWithString:HttpImgUrl(_infoModel.background)] placeholderImage:[UIImage imageNamed:@"llustration"]];
                       
                       for (NSDictionary *dic in _infoModel.publicPhotoList) {
                           [_photoArr addObject:dic];
                       }
                       
                       UIButton *sendMessageButton = [[UIButton alloc] initWithFrame:CGRectMake(0, KScreenHeight-50, KScreenWidth, 50)];
                       [sendMessageButton setTitle:@"发消息" forState:UIControlStateNormal];
                       [sendMessageButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                       sendMessageButton.backgroundColor = Theme_Color_Red;
                       sendMessageButton.alpha = 0.8;
                       [sendMessageButton addTarget:self action:@selector(clickSendMessageButton) forControlEvents:UIControlEventTouchUpInside];
                       
                       if (_infoModel.isFriend == 0 ) {
                           sendMessageButton.hidden = YES;
                       } else {
                           sendMessageButton.hidden = NO;
                       }
                       [self.view addSubview:sendMessageButton];

                       if (_infoModel.isFriend == 1) {
                           _giftBtn.hidden = YES;
                       }else{
                           _giftBtn.hidden = NO;
                       }
                       
                     [self.collectionView reloadData];
                   }];
    
    
    
}
//跳转到聊天界面
- (void)clickSendMessageButton {
    
    
    HQConversationViewController *conversationVC = [[HQConversationViewController alloc]init];
    conversationVC.conversationType = ConversationType_PRIVATE;
    NSString *str = _infoModel.uid;
    conversationVC.targetId = [NSString stringWithFormat:@"%@",str];
    conversationVC.title = _infoModel.nickName;
    conversationVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:conversationVC animated:YES];
}


//朋友圈状态
-(void)activeListRequest{
    WEAKSELF
    
    [HQHttpManager activeListWithUid:[HQHttpManager getUserId] herId:_UserId page:@1
                        successBlock:^(BOOL isSuccess, NSDictionary *resultDic) {
                            NSLog(@"陌生人朋友圈状态===========%@",resultDic);
                            if (isSuccess) {
                                
                                [self.dataSource removeAllObjects];
                            }
                            NSArray *array = resultDic[@"res"];
                            for (NSDictionary *dic in array) {
                                HRTimeLineModel *model = [HRTimeLineModel getTimeLineModelWithDictionary:dic];
                                [self.dataSource addObject:model];
                            }
                            
                            [weakSelf.collectionView reloadData];
                            
                            //        HRTimeLineModel *timeLineModel = self.dataArray[indexPath.row];
                            //        Active *model = [Active getActiveWithDictionary:(NSDictionary *)timeLineModel.active];
                            
                        }];
}

#pragma mark =====================拉黑 举报================
- (void)rightBtnClick{
    [self.actionSheetTitle showGGActionSheet];
}

-(GGActionSheet *)actionSheetTitle{
    if (!_actionSheetTitle) {
        
        _actionSheetTitle = [GGActionSheet ActionSheetWithTitleArray:@[@"举报",@"拉黑"] andTitleColorArray:@[[UIColor blackColor]] delegate:self];
        //取消按钮颜色设置
        _actionSheetTitle.cancelDefaultColor = [UIColor blackColor];
        //如果设置了选项颜色 当颜色数组和标题数组数量对不上时 多余标题使用选项默认颜色
        //如果设置了选项颜色 当颜色数组传空时，所有选项默认使用选项颜色
        //如果没设置选项颜色 数量对不上以及颜色数组为空时都使用默认黑色
        _actionSheetTitle.optionDefaultColor = [UIColor blackColor];
    }
    return _actionSheetTitle;
}

//弹框点击
-(void)GGActionSheetClickWithActionSheet:(GGActionSheet *)actionSheet Index:(int)index{
    
    if (index == 1) {
        self.alert =[[AlertViewExtension alloc]initWithFrame:CGRectMake(0, 0,KScreenWidth, KScreenHeight)];
        self.alert.delegate=self;
        [self.alert setbackviewframeWidth:KScreenWidth-50 Andheight:110];
        [self.alert settipeTitleStr:@"真的要将对方拉黑吗" Andfont:14];
        [self.view addSubview:self.alert];
    }else{
        
        _alertX = [ZXYAlertView alertViewDefault];
        _alertX.delegate = self;
        
        _alertX.title = @"选择举报类型";
        
        _alertX.buttonArray = _reportArr;
        [self.view addSubview:self.alertX];
        [_alertX show];
        
    }
    
}

//举报回调
- (void)alertView:(ZXYAlertView *)alertView clickedCustomButtonAtIndex:(NSInteger)buttonIndex {
    NSLog(@"---%ld",(long)buttonIndex);
    
    
    if (buttonIndex == 6) {
        
    }else{
        NSString *str = _reportArr[buttonIndex];
        
        
        [HcardHttpmanager getReportUid:[HQHttpManager getUserId] reportUid:_infoModel.uid Img:@"" reason:str success:^(id result) {
            if ([result[@"code"] isEqualToString:@"ok"]) {
                [SVProgressHUD showWithStatus:@"举报成功"];
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [SVProgressHUD dismiss];
                });
            }
        } failure:^(NSError *error) {
            
        }];
        

    }
    
}

//拉黑回调
-(void)clickBtnSelector:(UIButton *)btn
{
    if (btn.tag == 0) {
        
        [HcardHttpmanager blackFriendWithWid:_infoModel.uid Success:^(id result) {
            
            NSString *str =@"blackFriendNotification";
            [[NSNotificationCenter defaultCenter] postNotificationName:str object:@(NO)];
            [self.navigationController popViewControllerAnimated:YES];
        } failure:^(NSError *error) {
            
        }];
        [self.alert removeFromSuperview];
    }else{
        [self.alert removeFromSuperview];
    }
}

#pragma mark ==================喜欢  不喜欢==================
-(void)like_dontlikeClick:(UIButton *)sender{
    if (sender.tag == 100) {
        
        
        [HcardHttpmanager likeHerOrHimWithWid:_UserId state:@"1" successBlock:^(BOOL isSuccess, NSDictionary *resultDic) {
            if (isSuccess) {
                NSLog(@"我喜欢他========================");
            
                
    

                
                NSString *strright = @"rigthNSNotificationHomeStrang";
                [[NSNotificationCenter defaultCenter] postNotificationName:strright object:nil];

                [self.navigationController popViewControllerAnimated:YES];

                
            }
        } failure:^(NSError *error) {
            
        }];
        


    }else{
        [HcardHttpmanager likeHerOrHimWithWid:_UserId state:@"0" successBlock:^(BOOL isSuccess, NSDictionary *resultDic) {
            if (isSuccess) {
                NSLog(@"我不喜欢他========================");
                NSString *strleft = @"leftNSNotificationHomeStrang";
                [[NSNotificationCenter defaultCenter] postNotificationName:strleft object:nil];
                [self.navigationController popViewControllerAnimated:YES];

            }
        } failure:^(NSError *error) {
            
        }];
    }
}


#pragma mark ===============<UICollectionViewDataSource>===============

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    
    return 4;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    if (section == 0) {
        return 1;
    }else if(section == 1){
        return 1;
    }else if (section == 2){
        return 1;
    }else{
        if (self.dataSource.count == 0) {
            return 1;
        }else{
            return self.dataSource.count;

        }
    }
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        
        StrangerdataCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:StrangerCell forIndexPath:indexPath];
        cell.Cardmodel  = _Cardmodel;

        cell.infoModel = _infoModel;
        cell.delegate = self;
        return cell;
        
    }else if (indexPath.section == 1){
        
        PPImageScrollingTableViewCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
        
        cell.delegate = self;
        
        [cell setTag:[indexPath section]];
        [cell setBackgroundColor:[UIColor whiteColor]];
        [cell setImageData:_photoArr photo:_infoModel.photo];
        [cell setCategoryLabelText:@"公开相册" withColor:[UIColor blackColor]];
        [cell setImageTitleLabelWitdh:90 withHeight:90];
        [cell setCollectionViewBackgroundColor:[UIColor whiteColor]];
        return cell;
    }else if (indexPath.section == 2){
        UICollectionViewCell  *cell = [collectionView dequeueReusableCellWithReuseIdentifier:titleCellident forIndexPath:indexPath];
        
        
        
        UILabel *title = [[UILabel alloc] init];
        title.text = @"TA的动态";
        
        title.textAlignment = NSTextAlignmentLeft;
        title.font = [UIFont systemFontOfSize:16];
        
        title.frame = CGRectMake(15, 20, cell.width, 30);
        
        title.textColor = [UIColor blackColor];
        

        
        
        [cell.contentView addSubview:title];
//        [cell.contentView addSubview:imgView];·
        
        return cell;
    }else{
        
        
        if (self.dataSource.count >0) {
            FWBCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ident forIndexPath:indexPath];
            HRTimeLineModel *timeLineModel = self.dataSource[indexPath.row];
            Active *model = [Active getActiveWithDictionary:(NSDictionary *)timeLineModel.active];
            cell.model = model;
            return cell;
        }else{
            UICollectionViewCell  *cell = [collectionView dequeueReusableCellWithReuseIdentifier:imageCellIdent forIndexPath:indexPath];
            
            
            UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"empty_state_illustration"]];
            
            img.contentMode = UIViewContentModeScaleAspectFill;
            img.frame = CGRectMake(KScreenWidth/2-50, 30, 100, 200);
            [cell addSubview:img];
            
                    
            return cell;
        
        }
    }
    return nil;
}


#pragma mark ======================UICollectionView点击方法======================
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"%ld",(long)indexPath.section);
    if (indexPath.section == 0) {
        
        
    }else if(indexPath.section == 3){
        
        
        HRTimeLineModel *timeLineModel = self.dataSource[indexPath.row];
        Active *model = [Active getActiveWithDictionary:(NSDictionary *)timeLineModel.active];
        
        
        MstrangdetailsViewController *vc = [[MstrangdetailsViewController alloc] init];
        vc.model = model;
        
        
        
        CABasicAnimation *animation = nil;
        //缩放
        animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
        [animation setFromValue:@0.1];//设置起始值
        [animation setToValue:@1.];//设置目标值
        [animation setDelegate:self];//代理回调
        [animation setDuration:0.3];//设置动画时间，单次动画时间
        [animation setRemovedOnCompletion:NO];
        
        //you view need to replace
        [self.navigationController.view.layer addAnimation:animation forKey:nil];
        
        [self.navigationController pushViewController:vc animated:NO];
        
    }
    
}

#pragma mark ==================头部视图 nav滑动效果==================
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat offsetY = scrollView.contentOffset.y;
    if (offsetY >0) {
        CGFloat alpha = (offsetY+64) / 16 ;
        alpha = MIN(alpha, 1.0);
        self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor blackColor], NSFontAttributeName : FontP(15)};
        [_rightBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self setTabaritmimageStr:@"back"];
        
        [self.navigationController.navigationBar js_setBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:alpha]];
        
    } else {
        self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor], NSFontAttributeName : FontP(15)};
        [_rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self setTabaritmimageStr:@"back_w"];
        
        [self.navigationController.navigationBar js_setBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:0]];
    }
    
    //通过滑动的便宜距离重新给图片设置大小
    CGFloat yOffset = scrollView.contentOffset.y;
    if(yOffset<-kHomeImgHeight*SCREEN_WIDTH_RATIO47){
        
        if (self.headerImageView) {
            dispatch_async(dispatch_get_main_queue(), ^{
                CGRect frame = self.headerImageView.frame;
                frame.origin.y = yOffset;
                frame.size.height = -yOffset;
                self.headerImageView.frame = frame;
            });
            
        }
        
    }
    
}
#pragma mark =============按钮滑动消失================
//开始拖拽视图
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
{
    
    if (_infoModel.isFriend == 1) {
        _giftBtn.hidden = YES;
    }else{
        CATransition * animation = [CATransition animation];
        
        animation.duration = 0.5;    //  时间
        
        /**  type：动画类型
         *  pageCurl       向上翻一页
         *  pageUnCurl     向下翻一页
         *  rippleEffect   水滴
         *  suckEffect     收缩
         *  cube           方块
         *  oglFlip        上下翻转
         */
        //    animation.type = @"pageCurl";
        
        /**  type：页面转换类型
         *  kCATransitionFade       淡出
         *  kCATransitionMoveIn     覆盖
         *  kCATransitionReveal     底部显示
         *  kCATransitionPush       推出
         */
        animation.type = kCATransitionPush;
        
        //PS：type 更多效果请 搜索： CATransition
        
        /**  subtype：出现的方向
         *  kCATransitionFromRight       右
         *  kCATransitionFromLeft        左
         *  kCATransitionFromTop         上
         *  kCATransitionFromBottom      下
         */
        animation.subtype = kCATransitionFromLeft;
        
        [_giftBtn.layer addAnimation:animation forKey:nil];
        
        [UIView animateWithDuration:2.0 animations:^{
            _giftBtn.hidden = YES;
        }];

    }

    
    
}

//完成拖拽
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
{
    
    if (_infoModel.isFriend == 1) {
        _giftBtn.hidden = YES;
    }else{
        CATransition * animation = [CATransition animation];
        
        animation.duration = 0.5;    //  时间
        
        /**  type：动画类型
         *  pageCurl       向上翻一页
         *  pageUnCurl     向下翻一页
         *  rippleEffect   水滴
         *  suckEffect     收缩
         *  cube           方块
         *  oglFlip        上下翻转
         */
        //    animation.type = @"pageCurl";
        
        /**  type：页面转换类型
         *  kCATransitionFade       淡出
         *  kCATransitionMoveIn     覆盖
         *  kCATransitionReveal     底部显示
         *  kCATransitionPush       推出
         */
        animation.type = kCATransitionPush;
        
        //PS：type 更多效果请 搜索： CATransition
        
        /**  subtype：出现的方向
         *  kCATransitionFromRight       右
         *  kCATransitionFromLeft        左
         *  kCATransitionFromTop         上
         *  kCATransitionFromBottom      下
         */
        animation.subtype = kCATransitionFromRight;
        
        [_giftBtn.layer addAnimation:animation forKey:nil];
        
        [UIView animateWithDuration:2.0 animations:^{
            _giftBtn.hidden = NO;
        }];

    }
    
}

#pragma mark ==================点击相册方法==================
- (void)scrollingTableViewCell:(PPImageScrollingTableViewCell *)scrollingTableViewCell didSelectImageAtIndexPath:(NSIndexPath*)indexPathOfImage atCategoryRowIndex:(NSInteger)categoryRowIndex
{
    
    
    
    
    
    
    NSInteger count = _photoArr.count;
    NSMutableArray *photos = [NSMutableArray arrayWithCapacity:count];
    // 1.封装图片数据
    if (count > 0) {
        for (int i = 0; i<count; i++) {
            //公开相册有数据
            NSDictionary *images = [self.photoArr objectAtIndex:i];
            NSString *url = [images objectForKey:@"url"];
            MJPhoto *photo = [[MJPhoto alloc] init];
            photo.url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",HttpImgUrlString,url]]; // 图片路径
            [photos addObject:photo];
        }
    }else{
        //无数据
        MJPhoto *photo = [[MJPhoto alloc] init];
        photo.url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",HttpImgUrlString,_infoModel.photo]]; // 图片路径
        [photos addObject:photo];
    }
    
    // 2.显示相册
    MJPhotoBrowser *browser = [[MJPhotoBrowser alloc] init];
    browser.currentPhotoIndex = indexPathOfImage.row; // 弹出相册时显示的第一张图片是？
    browser.photos = photos; // 设置所有的图片
    [browser show];
    
}




@end
